/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.domain.bd;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Rdelacruz
 */
public class Registro {    
    Tabla tabla;
    
    Map<String,String> valores;//son tuplas campo-valor

    public Registro() {
        valores = new HashMap<String,String>();
    }
    
    public void addValor(String campo, String valor) {
        
        //Cambiando ñ por nh
        String campo1 = campo.toLowerCase();
        if(campo1.contains("ñ"))
            campo = campo1.replace("ñ", "nh");
        
        valores.put(campo, valor);
    }

    public String scriptInsert() {
        StringBuilder sb = new StringBuilder();
        sb.append("insert into ");
        sb.append(tabla.getNombre()+"(");
        for (Map.Entry<String, String> e : valores.entrySet()) {
            //System.out.println(entry.getKey() + "/" + entry.getValue());
            sb.append(e.getKey()+",");
        }
        int n = sb.length();        
        sb.delete(n-1, n);//borrando la coma
        
        sb.append(") values (");
        for (Map.Entry<String, String> e : valores.entrySet()) {
            //System.out.println(entry.getKey() + "/" + entry.getValue());
            sb.append("'"+e.getValue()+"',");//EXPORTANDO TODO COMO TIPO TEXTO
        }
        n = sb.length();
        sb.delete(n-1, n);//borrando la coma
        sb.append("); ");
        
        return sb.toString();
    }
    
}
